package cosc617_blackteam;

import java.math.BigDecimal;
import java.util.ArrayList;


/**
 * Iterator of all menuItems in given menu that are <= given price
 * @author Laura Semesky
 */
public class PriceMenuIterator implements I_MenuIterator {
	ArrayList<MenuItem> menu; //menu to iterate over
	private int index; //current index
	private BigDecimal price; //price to compare menu items to
	
	PriceMenuIterator(ArrayList<MenuItem> menu, BigDecimal price){
		index = 0;
		this.menu = menu;
		this.price = price;
	}
	
	@Override
	public boolean hasNext() {
		while (index < menu.size()){
			//gets menuItem at index and checks if price is equal to given price
			if (menu.get(index).getPrice().compareTo(price) <= 0)
				return true;
			index ++;
		}
		return false;
	}

	@Override
	public MenuItem next() {
		
		MenuItem output;
		if(hasNext()) //make sure there is a next and index is pointing to it
			output = menu.get(index);
		else output = null;
		index++;
		return output;
	}

	@Override
	public void remove() {
		throw new UnsupportedOperationException();
		
	}

}
